<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script src="./OL_SDK/include-openlayers-local.js"></script>
    <script src="./libs/gaode.js"></script>
    <script src="./utils/delFeature.js"></script>
    <script src="./utils/Query.js"></script>
    <script src="./utils/createDraw.js"></script>
</head>

<body>
    <button onclick="activeDraw()">激活画笔</button>
    <div id="map">
    </div>
    <script>
        var docLayer = new Zondy.Map.Doc("", "attr_city", {

        })
        var map = new ol.Map({
            target: "map",
            layers: [gaode, docLayer],
            view: new ol.View({
                projection: 'EPSG:4326',
                center: [114.30, 30.50],
                zoom: 4
            })
        })
        /* 1、实现拉框查询获取fids */
        /* 2、调用删除服务 */
        var source = new ol.source.Vector({})
        var layer = new ol.layer.Vector({
            source
        })
        map.addLayer(layer);
        let draw = null;
        function activeDraw() {
            draw = createDraw({
                type: "Box",
                source,
                callback: handleDraw
            })
            map.addInteraction(draw);
        }
        const service = {
            name: "attr_city",
            layerId: 0
        }
        function handleDraw(feature) {

            map.removeInteraction(draw);
            source.clear()
            /* 调用几何查询 获取fids */


            Query.queryByGeom({
                feature,
                service,
                callback: handleQuery
            })
        }

        function handleQuery(res) {
            console.log(res);
            let fids = res.map(item => item.id_);
            delFeature({
                service,
                fids,
                docLayer
            })
        }
    </script>
</body>

</html>